package com.hymjweb.demo.hymj.finance_manage.pay.controller;

import com.alibaba.fastjson.JSONObject;
import com.hymjweb.demo.framework.result.BaseResultMap;
import com.hymjweb.demo.framework.sys.BaseController;
import com.hymjweb.demo.framework.sys.SysConstant;
import com.hymjweb.demo.hymj.finance_manage.pay.service.CwPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/pages/finance_manage/pay")
public class CwPayController extends BaseController {

    @Autowired
    private CwPayService cwPayService;

    @RequestMapping("/showNativeBillPay")
    public String showNativeBillPay() {
        return "/pages/finance_manage/pay/nativeBillPay";
    }

    @RequestMapping("/showAirMasterBillPay")
    public String showAirMasterBillPay() {
        return "/pages/finance_manage/pay/airMasterBillPay";
    }

    @RequestMapping("/showAutoMasterBillPay")
    public String showAutoMasterBillPay() {
        return "/pages/finance_manage/pay/autoMasterBillPay";
    }

    @RequestMapping("/showPayClearedList")
    public String showPayClearedList() {
        return "/pages/finance_manage/pay/payBillClearedList";
    }

    @RequestMapping("/queryPayClearedList")
    @ResponseBody
    public Object queryPayClearedList(@RequestParam(required = false) Map param) {
        return cwPayService.getPageList(param);
    }


    @RequestMapping("/queryNatvieBillList")
    @ResponseBody
    public Object queryNatvieBillList(@RequestParam(required = false) Map param) {
        return cwPayService.getNativeBillPageList(param);
    }


    @RequestMapping("/queryFlightMasterBillList")
    @ResponseBody
    public Object queryFlightMasterBillList(@RequestParam(required = false) Map param) {
        return cwPayService.getAirMasterBillPageList(param);
    }


    @RequestMapping("/queryAutoMasterBillList")
    @ResponseBody
    public Object queryAutoMasterBillList(@RequestParam(required = false) Map param) {
        return cwPayService.getAutoMasterBillPageList(param);
    }


    @RequestMapping("/clearedBillCharge")
    @ResponseBody
    public Object clearedBillCharge(@RequestBody JSONObject clearedObj) throws Exception {
        if (clearedObj == null || clearedObj.isEmpty()) {
            throwException("费用结清参数错误!");
        }

        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("费用结清成功!");

        int effectRows = cwPayService.clearedBillCharge(clearedObj);

        if (effectRows <= SysConstant.INT_ZERO) {
            baseResultMap.setOk(false);
            baseResultMap.setMessage("费用结清失败!");
        }

        return baseResultMap;
    }


}
